package com.xique.client.controller;

import com.xique.client.api.IWxAppPlatformApi;
import com.xique.client.bean.domain.ParkDeviceNew;
import com.xique.client.bean.domain.ParkLane;
import com.xique.client.service.service.IParkDeviceNewService;
import com.xique.client.service.service.IParkLaneService;
import com.xique.common.core.web.controller.BaseController;
import com.xique.common.core.web.domain.AjaxResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 微信车场管理端接口
 * 通道
 */
@RestController
@RequestMapping("/app")
@Slf4j
public class WxAppLaneController extends BaseController {

    @Autowired
    private IParkDeviceNewService parkDeviceNewService;

    @Autowired
    private IWxAppPlatformApi wxAppPlatformApi;

    @Autowired
    private IParkLaneService parkLaneService;

    /**
     * 通道列表
     * @return
     */
    @GetMapping("/laneList")
    public AjaxResult parkLaneList(Long parkId){
        ParkDeviceNew parkDeviceNew = new ParkDeviceNew();
        parkDeviceNew.setParkId(parkId);
        parkDeviceNew.setIsMain("Y");
        parkDeviceNew.setStatus("normal");
        parkDeviceNew.setRecordStatus("normal");
        List<ParkDeviceNew> parkDeviceNewList = parkDeviceNewService.selectParkDeviceNewList(parkDeviceNew);
        ParkLane parkLane;
        if(!CollectionUtils.isEmpty(parkDeviceNewList)){
            for(ParkDeviceNew parkDeviceNew1 : parkDeviceNewList){
                parkLane = parkLaneService.selectParkLaneById(parkDeviceNew1.getLaneId());
                parkDeviceNew1.setLaneType(null != parkLane ? parkLane.getLaneType() : "0");
                parkDeviceNew1.setLaneName(null != parkLane ? parkLane.getName() : parkDeviceNew1.getName());
            }
        }
        Map<String, Object> map = new HashMap<>();
        map.put("list", parkDeviceNewList);
        return AjaxResult.success("成功", map);
    }


    /**
     * 获取远程访问相机路径
     * @param code
     * @return
     */
    @GetMapping("/getAppDeviceWebUrl")
    @ResponseBody
    public AjaxResult getDeviceWebUrlAPP(String code){
        return wxAppPlatformApi.getAppDeviceWebUrl(code);
    }

}
